﻿
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ease Template Manual - SYSTN.COM</title>
<style>
<!--

td { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; color:#000000   }
.style8 {
background-color: #FFFFFF;
}

p { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; color:#000000   }
.style10 {
font-size: 9px;
font-family: "Arial Unicode MS";
text-align: right;
}
-->
</style>
</head>

<table class="style4" style="WIDTH: 100%" cellSpacing="0" cellPadding="0" border="0" id="table1">
	<tr>
		<td class="style8">
		<table style="WIDTH: 100%" cellSpacing="8" cellPadding="8" border="0" id="table2">
			<tr>
				<td style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #000000">
				<table id="table3" style="BORDER-COLLAPSE: collapse" borderColor="#808080" cellPadding="4" width="100%" align="left" border="0">
					<tr>
						<td vAlign="top" colSpan="2" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #000000">
						<font style="FONT-SIZE: 30px" color="#94a7b1">
						<font face="Arial">Ease Template Manual</font> </font>
						<font style="FONT-SIZE: 10px" face="Arial" color="#94a7b1">
						Version:E3</font></td>
					</tr>
					<tr>
						<td vAlign="top" width="4" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #000000">　</td>
						<td vAlign="top" align="left" width="98%" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #000000">
						<table class="TableBorder" cellSpacing="1" cellPadding="0" width="100%" border="0" id="table5">
							<tr>
								<td class="TableMiddle">
								每个程序都会涉及到循环处理，引入循环到模板是模板引擎一个比较有特色的功能。<br>
								<br>
								Ease Template 为了方便应用将在每次循环时增加一个递增变量<font color="#dd0000">$_i</font> 
								，用户可以使用此变量来制作循环无数据等提示。<br>
								<br>
								Ease Template提供了两种循环方式：foreach、while<br>
								<br>
								先来介绍foreach用法（为了方便在Ease 
								Template模板中的应用，对用法进行了一定的优化）。<br>
								<br>
								test_4.php<br>
　<ol style="text-align: left; margin: 0px; padding-left: 40px; padding-right: 1px; padding-top: 1px; padding-bottom: 1px; background: #e1e7f0">
									<li style="background: #ffffff url('images/code_bg.gif')">
									<code><span style="COLOR: #000000">
									<span style="COLOR: #0000bb">&lt;?php &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #007700">include</span><span style="COLOR: #dd0000">&quot;./template.ease.php&quot;</span><span style="COLOR: #007700">; 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">$tpl&nbsp;</span><span style="COLOR: #007700">=&nbsp;new&nbsp;</span><span style="COLOR: #0000bb">template</span><span style="COLOR: #007700">(); 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #ff8000">
									//参与循环的数组 &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">$user_list&nbsp;</span><span style="COLOR: #007700">=&nbsp;array( 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;&nbsp;array( &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #dd0000">'name'&nbsp;&nbsp;</span><span style="COLOR: #007700">=&gt;&nbsp;</span><span style="COLOR: #dd0000">'md-chinese'</span><span style="COLOR: #007700">, 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #dd0000">'pass'&nbsp;&nbsp;</span><span style="COLOR: #007700">=&gt;&nbsp;</span><span style="COLOR: #dd0000">'654321'</span><span style="COLOR: #007700">, 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;&nbsp;), &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;&nbsp;array( &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #dd0000">'name'&nbsp;&nbsp;</span><span style="COLOR: #007700">=&gt;&nbsp;</span><span style="COLOR: #dd0000">'test'</span><span style="COLOR: #007700">, 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #dd0000">'pass'&nbsp;&nbsp;</span><span style="COLOR: #007700">=&gt;&nbsp;</span><span style="COLOR: #dd0000">'123456'</span><span style="COLOR: #007700">, 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;&nbsp;) &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									); &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">$tpl</span><span style="COLOR: #007700">-&gt;</span><span style="COLOR: #0000bb">set_file</span><span style="COLOR: #007700">(</span><span style="COLOR: #dd0000">'test_4'</span><span style="COLOR: #007700">); 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">$tpl</span><span style="COLOR: #007700">-&gt;</span><span style="COLOR: #0000bb">p</span><span style="COLOR: #007700">(); 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">?&gt;</span>
									</span></code></li>
								</ol>
								<br>
								test_4.htm<br>
　<ol style="text-align: left; margin: 0px; padding-left: 40px; padding-right: 1px; padding-top: 1px; padding-bottom: 1px; background: #e1e7f0">
									<li style="background: #ffffff url('images/code_bg.gif')">
									<code><span style="COLOR: #000000">循环代码:&lt;br&gt; 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">
									&lt;!--&nbsp;$user_list&nbsp;AS&nbsp;$user&nbsp;--&gt;</font> &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　ID:<font color="#007700">{_i}</font>&nbsp; &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　账号：<font color="#007700">{user['name']}</font> 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　密码：<font color="#007700">{user['pass']}</font>&lt;br&gt;&lt;br&gt; 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;END&nbsp;--&gt;</font> &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									无法得到循环数据代码:&lt;br&gt; &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">
									&lt;!--&nbsp;$user_list1&nbsp;AS&nbsp;$users&nbsp;--&gt;</font> &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　ID:<font color="#007700">{_i}</font>&nbsp; &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　账号：<font color="#007700">{users['name']}</font> 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　密码：<font color="#007700">{users['pass']}</font>&lt;br&gt;&lt;br&gt; 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;END&nbsp;--&gt;</font> &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">
									&lt;!--&nbsp;用于判断提示检测的方法$_i==0&nbsp;--&gt;</font> &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;IF[$_i==0]&nbsp;--&gt;</font> 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&lt;font&nbsp;color=&quot;#800000&quot;&gt;抱歉，没有得到循环数据!&lt;/font&gt; &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;END&nbsp;--&gt;</font></span>
									</code></li>
								</ol>
								<br>
								<br>
								现在我们进入更复杂的循环操作：while在模板中对数据库的操作。如果将数据库对象引入模板则不用在循环后得到数组再赋值给模板，节省了大量时间以及循环次数。<br>
								<br>
								测试数据库内容:<br>
								[text character set utf8]<br>
								CREATE TABLE `users` (<br>
								`uid` INT( 3 ) NOT NULL AUTO_INCREMENT PRIMARY 
								KEY ,<br>
								`username` VARCHAR( 64 ) NOT NULL ,<br>
								`password` VARCHAR( 32 ) NOT NULL <br>
								) TYPE = MyISAM DEFAULT CHARSET=utf8 ;<br>
								<br>
								INSERT INTO `users` (`uid`, `username`, 
								`password`) VALUES (1, 'md-chinese', '123456'),<br>
								(2, 'ease template', 'systn');<br>
								[/text character set utf8]<br>
								<br>
								这里为了体现数据库操作效果，我们载入一个简单的数据库类，连接本地数据库，并且连接test库表。<br>
								<br>
								test_5.php<br>
　<ol style="text-align: left; margin: 0px; padding-left: 40px; padding-right: 1px; padding-top: 1px; padding-bottom: 1px; background: #e1e7f0">
									<li style="background: #ffffff url('images/code_bg.gif')">
									<code><span style="COLOR: #000000">
									<span style="COLOR: #0000bb">&lt;?php &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #007700">include</span><span style="COLOR: #dd0000">&quot;./template.ease.php&quot;</span><span style="COLOR: #007700">; 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #ff8000">//引入数据库类 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #007700">include</span><span style="COLOR: #dd0000">&quot;./mysql.php&quot;</span><span style="COLOR: #007700">; 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">$tpl&nbsp;</span><span style="COLOR: #007700">=&nbsp;new&nbsp;</span><span style="COLOR: #0000bb">template</span><span style="COLOR: #007700">(); 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #ff8000">//声明数据库 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">$db&nbsp;</span><span style="COLOR: #007700">=&nbsp;new&nbsp;</span><span style="COLOR: #0000bb">Dirver</span><span style="COLOR: #007700">(); 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #ff8000">//连接数据库 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">$db</span><span style="COLOR: #007700">-&gt;</span><span style="COLOR: #0000bb">DBLink</span><span style="COLOR: #007700">(</span><span style="COLOR: #dd0000">'localhost'</span><span style="COLOR: #007700">,</span><span style="COLOR: #dd0000">'root'</span><span style="COLOR: #007700">,</span><span style="COLOR: #dd0000">''</span><span style="COLOR: #007700">,</span><span style="COLOR: #dd0000">'test'</span><span style="COLOR: #007700">); 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #ff8000">//索引数据 &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">$query&nbsp;</span><span style="COLOR: #007700">=&nbsp;</span><span style="COLOR: #0000bb">$db</span><span style="COLOR: #007700">-&gt;</span><span style="COLOR: #0000bb">query</span><span style="COLOR: #007700">(</span><span style="COLOR: #dd0000">&quot;SELECT&nbsp;*&nbsp;FROM&nbsp;users&quot;</span><span style="COLOR: #007700">); 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">$tpl</span><span style="COLOR: #007700">-&gt;</span><span style="COLOR: #0000bb">set_file</span><span style="COLOR: #007700">(</span><span style="COLOR: #dd0000">'test_5'</span><span style="COLOR: #007700">); 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">$tpl</span><span style="COLOR: #007700">-&gt;</span><span style="COLOR: #0000bb">p</span><span style="COLOR: #007700">(); 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									</span><span style="COLOR: #0000bb">?&gt;</span>
									</span></code></li>
								</ol>
								<br>
								<br>
								此次模板中与foreach循环一样也提供了一个没有数据的循环，将会提示没有数据效果。<br>
								<br>
								test_5.htm <br>
　<ol style="text-align: left; margin: 0px; padding-left: 40px; padding-right: 1px; padding-top: 1px; padding-bottom: 1px; background: #e1e7f0">
									<li style="background: #ffffff url('images/code_bg.gif')">
									<code><span style="COLOR: #000000">循环代码:&lt;br&gt; 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;while:$user&nbsp;=&nbsp;$db-&gt;fetch_array($query)&nbsp;--&gt;</font> 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　ID:<font color="#007700">{_i}</font>&nbsp; &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　账号：<font color="#007700">{user['username']}</font> 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　密码：<font color="#007700">{user['password']}</font>&lt;br&gt;&lt;br&gt; 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;END&nbsp;--&gt;</font> &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									无法得到循环数据代码:&lt;br&gt; &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;while:$users&nbsp;=&nbsp;$db-&gt;fetch_array($query1)&nbsp;--&gt;</font> 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　ID:<font color="#007700">{_i}</font>&nbsp; &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　账号：<font color="#007700">{users['username']}</font> 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									　　密码：<font color="#007700">{users['password']}</font>&lt;br&gt;&lt;br&gt; 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;END&nbsp;--&gt;</font> &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;用于判断提示检测的方法$_i==0&nbsp;--&gt;</font> 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;IF[$_i==0]&nbsp;--&gt;</font> 
									&nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									&lt;font&nbsp;color=&quot;#800000&quot;&gt;抱歉，没有得到循环数据!&lt;/font&gt; &nbsp;
									</li>
									<li style="background: #ffffff url('images/code_bg.gif')">
									<font color="#808080">&lt;!--&nbsp;END&nbsp;--&gt;</font></span>
									</code></li>
								</ol>
								</td>
							</tr>
						</table>
						</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td class="style8" style="HEIGHT: 21px">
		<table class="style4" cellSpacing="0" cellPadding="0" align="right" id="table6">
			<tr>
				<td style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #000000">
				<img height="13" src="images/copyright_left.gif" width="3"></td>
				<td class="style10" style="WIDTH: 240px" background="images/copyright_bg.gif">
				Copyright 2005 - 2008 <a href="http://www.systn.com" target="_blank"><font color="#000000">SYSTN.COM</font></a>&nbsp;&nbsp;&nbsp;</td>
				<td style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #000000">
				<img height="13" src="images/copyright_right.gif" width="2"></td>
			</tr>
		</table>
		</td>
	</tr>
</table>
